﻿#region Opis pliku
//-----------------------------------------------------------------------------
// Armor.cs
// Autor: Jan Fraś
// 30.10.2012
//-----------------------------------------------------------------------------
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace pogra
{
    /// <summary>
    /// osłony czołgu. Przyjmują na siebie część obrażeń.
    /// Zniszczona osłona przestaje przyjmować obrażenia i drukuje inną teksturę. 
    /// Czołg ma 4 osłony - z każdej storny po jednej.
    /// </summary>
    class Armor
    {
        Texture2D tex;
        int condition;
        Rectangle cliprect;
        Tank owner;
        float layer;

        public Armor(Texture2D textura,Tank owner, Rectangle cliprect, float layer)
        {
            this.layer = layer;
            condition = 500;
            tex = textura;
            this.cliprect = cliprect;
            this.owner = owner;
        }

        internal int takehit(int hit)
        {
            if (condition > 0)
            {
                condition -= hit;
                return 0;
            }
            else
            {
                return hit;
            }
        }

        public bool Update()
        {
            return condition > 0;
        }

        public void Draw( ExtendedSpriteBatch exSpriteBatch, Color color)
        {
            Color tmp = new Color();
            if (condition < 100 && owner.Health > 0)
            {
                tmp = Color.Red;
            }
            else
               tmp = color;


            exSpriteBatch.Draw(tex, owner.Position, cliprect, tmp, owner.Rotation,new Vector2(cliprect.Width,cliprect.Height)/2, 1, SpriteEffects.None, layer);
        }

    }
}
